#include <signal.h>
#include <unistd.h>
#include <math.h>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <sys/types.h>
#include <time.h>


//#include <wx/wx.h>
//#include "wxSPAN.h"
#include "SPAN_functions.h"
#define SEED 35791246


void bubble_srt(int a[], int n ){
	int i, j=0;
	int t=0;
	for(i = 0; i < n; i++){
		for(j = 1; j < (n-i); j++){
			if(a[j-1] > a[j]){
				t = a[j-1];
				a[j-1]=a[j];
				a[j]=t;
			}
		}
	}
}

int main(int argc, char *argv[]){
	char function1[] = "INT";
	char function2[] = "PI";
	char function3[] = "SORT";
	char function4[] = "PRIME";

	//-----------------------------------------------------------

	SPAN_initialize ();

	SPAN_start("test");
	time_t t;
	unsigned  int a, b,c;
	double i;
	a=1;b=2;c=3;i=0;
	while(i<100000000){
		a=a+b;
		b=a+c;
		i++;}
	time(&t);
	printf("INT %s\n", ctime(&t));

	//    sleep(5);
	//SPAN_stop();

	//-----------------------------------------------------------

	//SPAN_initialize ();
	//SPAN_start(function2);
	time(&t);
	printf("begin PI %s\n", ctime(&t));
	int niter=10000;
	double x,y;
	int v,count=0;
	double w;
	double pi;
	srand(SEED);
	count=0;
	for ( v=0; v<niter; v++) {
		x = (double)rand()/RAND_MAX;
		y = (double)rand()/RAND_MAX;
		w = x*x+y*y;
		if (w<=1) count++;
	}
	pi=(double)count/niter*4;
	time(&t);
	printf("end PI %s\n", ctime(&t));

	//    sleep(5);
	//SPAN_stop();

	//------------------------------------------------------------


	//SPAN_initialize ();
	//SPAN_start(function3);
	time(&t);
	printf("begin sort %s\n", ctime(&t));
	int m[5120];
	int p,h;
	p = 5120;
	for(h=0;h<p;h++)
		m[h]=rand();

	bubble_srt(m,p);
	time(&t);
	printf("end sort %s\n", ctime(&t));
	sleep(1);
	//SPAN_stop();

	//-------------------------------------------------------------


	//SPAN_initialize ();
	//SPAN_start(function4);
	time(&t);
	printf("begin prime %s\n", ctime(&t));
	int f,q;
	int z=1;
	f=3000;
	while(z<=f)
	{
		c=0;
		for(q=1;q<=z;q++)
		{
			if(z%q==0)
				c++;
		}
		if(c==2)
			;
		//         printf("%d",z);
		z++;
	}
	//    time(&t);
	//    printf("end prime %s\n", ctime(&t));
	SPAN_stop();
	//MyApp* app=new MyApp();
	//wxApp::SetInstance(app);
	//return wxEntry(argc,argv);


	return 0;


}
